#define _CRT SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int alternatingSubarray(vector<int>& nums) {
        int n = nums.size();
        int pre = 0, next = pre + 1, sum = 1;
        int max = 0;
        int flag = 1;
        while (next < n)
        {
            if (flag == 1)
            {
                if (nums[next] - nums[pre] == 1)
                {
                    next++;
                    pre++;
                    sum++;
                    flag = 0;
                }
                else
                {
                    next++;
                    pre++;
                    max = max > sum ? max : sum;
                    sum = 1;
                }
            }
            else if (flag == 0)
            {
                if (nums[pre] - nums[next] == 1)
                {
                    next++;
                    pre++;
                    sum++;
                    flag = 1;
                }
                else
                {
                    max = max > sum ? max : sum;
                    sum = 1;
                    flag = 1;
                }
            }
        }
        max = max > sum ? max : sum;
        if (max != 1)
            return max;
        else
            return -1;
    }
};
int main()
{
    Solution s;
    vector<int> arr(20, 0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int ret=s.alternatingSubarray(arr);
    cout << ret;
    return 0;
}

